<template>
  <div>
    <x-header style="background-color:#10aeff;">报表图表</x-header>
    <div height="100" class="ui-row" style="margin: 20px; height: 100px;">
      <div class="left-item ui-col " style="padding-left: 10px; padding-right: 10px;">
        <div style="height: 100px;">
          <div class="ui-navigator">
            <div class="title">公司设备总数</div>
            <span class="ui-text">
              <!---->
              <span>{{sum.sc+sum.js+sum.gl}}</span>
              <!---->
            </span>
          </div>
        </div>
      </div>
      <div class="ui-col" style="flex: 0 0 20px;">
        <div class="ui-col-content" style="height: 100px;"></div>
      </div>
      <div class="right-item ui-col" style="padding-left: 10px; padding-right: 10px;">
        <div style="height: 100px;">
          <div class="ui-navigator">
            <div class="title">生产用设备</div>
            <span class="ui-text">
              <!---->
              <span>{{sum.sc}}</span>
              <!---->
            </span>
          </div>
        </div>
      </div>
    </div>

    <div height="100" class="ui-row" style="margin: 20px; height: 100px;">
      <div class="left-item1 ui-col " style="padding-left: 10px; padding-right: 10px;">
        <div style="height: 100px;">
          <div class="ui-navigator">
            <div class="title">管理用设备</div>
            <span class="ui-text">
              <!---->
              <span>{{sum.gl}}</span>
              <!---->
            </span>
          </div>
        </div>
      </div>
      <div class="ui-col" style="flex: 0 0 20px;">
        <div class="ui-col-content" style="height: 100px;"></div>
      </div>
      <div class="right-item1 ui-col" style="padding-left: 10px; padding-right: 10px;">
        <div style="height: 100px;">
          <div class="ui-navigator">
            <div class="title">技术用设备</div>
            <span class="ui-text">
              <!---->
              <span>{{sum.js}}</span>
              <!---->
            </span>
          </div>
        </div>
      </div>
    </div>
    <div style="text-align:center">
      数据不全，后期再开发其他报表
      <!-- <v-chart ref="demo" :data="sum.deviceGroupByDepartments">
        <v-scale x field="department" />
        <v-scale y field="num" />
        <v-bar />
        <v-tooltip :show-item-marker="false" />
      </v-chart> -->
      <!-- <v-chart ref="demo" :data="sum.deviceGroupByDepartments">
        <v-scale x field="department" />
        <v-scale y field="num" />
        <v-bar />
        <v-tooltip :show-item-marker="false" />
      </v-chart> -->
      <!-- <v-chart ref="demo" :data="data">
        <v-bar />
        <v-tooltip :show-item-marker="false" />
      </v-chart> -->
    </div>
  </div>
</template>

<script>
import {
  LoadMore,
  XHeader,
  VChart,
  VLine,
  VArea,
  VTooltip,
  VLegend,
  VBar,
  XButton,
  VScale
} from "vux";
import axios from "axios";
export default {
  data() {
    return {
      sum: {
        sc: 0,
        gl: 0,
        js: 0,
        deviceGroupByDepartments: []
      },
      data: [
        { year: "1951 年", sales: 38 },
        { year: "1952 年", sales: 52 },
        { year: "1956 年", sales: 61 },
        { year: "1957 年", sales: 145 },
        { year: "1958 年", sales: 48 },
        { year: "1959 年", sales: 38 },
        { year: "1960 年", sales: 38 },
        { year: "1962 年", sales: 38 }
      ]
    };
  },
  components: {
    LoadMore,
    XHeader,
    VChart,
    VLine,
    VArea,
    VTooltip,
    VLegend,
    VBar,
    XButton,
    VScale
  },
  created() {
    this.getInfo();
  },

  methods: {
    async getInfo() {
      let department = this.$store.state.info.user.department;
      let company = this.$store.state.info.user.company;
      if (this.$store.state.info.role[0].role_name == "系统管理员") {
        department = "";
      }
      if (this.$store.state.info.role[0].role_name == "主管领导") {
        department = "";
      }

      let instance = axios.create({
        headers: { "content-type": "application/json" }
      });
      try {
        let info = await instance.post(`http://192.168.10.19:4000/graphql`, {
          query: `{sc:deviceList_Type_Count_By_Company_Department(type:"生产",department:"${department}",company:"${company}"),
                   gl:deviceList_Type_Count_By_Company_Department(type:"管理",department:"${department}",company:"${company}"),
                   js:deviceList_Type_Count_By_Company_Department(type:"技术",department:"${department}",company:"${company}"),
                   deviceGroupByDepartments(company:"${company}"){department,num}
                   }`
        });
        this.sum.sc = info.data.data.sc;
        this.sum.gl = info.data.data.gl;
        this.sum.js = info.data.data.js;

        for (const key in info.data.data.deviceGroupByDepartments) {
          this.sum.deviceGroupByDepartments.push(
            info.data.data.deviceGroupByDepartments[key]
          );
        }
      } catch (error) {
        console.error(error);
      }
    }
  }
};
</script>

<style scoped>
.ui-row {
  position: relative;
  -webkit-flex: 1;
  flex: 1;
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content: center;
}
.left-item {
  background: #ff4545 no-repeat 95% 100%;
  background-size: 50px;
  box-shadow: 0 4px 16px 0 #ff4545;
  border-radius: 5px;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.left-item1 {
  background: #09bb07 no-repeat 95% 100%;
  background-size: 50px;
  box-shadow: 0 4px 16px 0 #09bb07;
  border-radius: 5px;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.right-item {
  background: #0070bb no-repeat 95% 95%;
  background-size: 50px;
  box-shadow: 0 4px 16px 0 #0070bb;
  border-radius: 5px;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.right-item1 {
  background: #ff6f00 no-repeat 95% 95%;
  background-size: 50px;
  box-shadow: 0 4px 16px 0 #ff6f00;
  border-radius: 5px;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.ui-col {
  position: relative;
  min-width: 0;
  display: -webkit-flex;
  display: flex;
  -webkit-flex: 1;
  flex: 1;
  -webkit-align-items: center;
  align-items: center;
  height: 100%;
  min-width: 0;
  -webkit-flex-direction: column;
  flex-direction: column;
  width: 100%;
}
.title {
  color: #fff;
  font-size: 14px;
  margin-top: 10px;
  margin-bottom: 10px;
}
.ui-text {
  color: #fff;
  font-size: 24px;
}
</style>
